package org.sanguine.study.hometasks.second;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class Task4 {
	
	public static class SetOfInteger {
		private Set<Integer> set = new HashSet<>();
		
		/**
		 * Add new number in set
		 * @param number
		 * @return - true, if content of set changed
		 */
		
		public boolean add(Integer number) {
			return set.add(number);
		}
		
		/**
		 * Remove number from set
		 * @param number
		 * @return - true, if content of set changed
		 */
		
		public boolean remove(Integer number) {
			return set.remove(number);
		}
		
		/**
		 * Get content of set
		 * @return - content of set
		 */
		
		public Collection<Integer> getContent() {
			return set;
		}
		
		public SetOfInteger() {
			
		}
		
		public SetOfInteger(Integer number) {
			this();
			add(number);
		}
		
		public SetOfInteger(Collection<Integer> numbers) {
			this();
			set.addAll(numbers);
		}
		
		/**
		 * Make intersection of set with another set
		 * @param another set
		 * @return intersection of two sets
		 */
		
		public SetOfInteger intersection(SetOfInteger another) {
			SetOfInteger newSet = new SetOfInteger();
			if (!set.isEmpty()) {
				SetOfInteger tmpSet = new SetOfInteger(set);
				if (another != null)
					for (Integer value : another.getContent())
						if (!tmpSet.add(value)) newSet.add(value);
			}
			
			return newSet;
		}
		
		/**
		 * Make union of set with another set
		 * @param another set
		 * @return union of two sets
		 */

		public SetOfInteger union(SetOfInteger another) {
			SetOfInteger newSet = new SetOfInteger(set);
			if (another != null)
				for (Integer value : another.getContent()) newSet.add(value);
			return newSet;
		}

	}

}
